/*
 * @Description:: 请补充填写
 * @Version: 1.0
 * @Author: 小白
 * @Date: 2025-07-18 10:44:49
 * @LastEditors: 小白
 * @LastEditTime: 2025-11-18 19:31:31
 * @FilePath: /tmsadmin/src/router/index.ts
 */
import { store } from '@/store/index';
/*
 * @Author: your name
 * @Date: 2022-03-13 08:57:33
 * @LastEditTime: 2025-07-21 14:12:41
 * @LastEditors: 小白
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \tms-admin\src\router\index.ts
 */
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import Main from '@/layout/Main.vue'
// import Main from '../layout/secondMain.vue'
import nprogress from 'nprogress'
import { getToken } from '../plugins/cookie'
import 'nprogress/nprogress.css'
const routes: RouteRecordRaw[] = [
  {
    path: '/',
    component: Main,
    children: [
       // 官网管理员 4
      // 仓库管理员 3
      // 合同管理员 2
      // 司机1
      // 录入员 0
     {
        path: '/', // 默认子路由
        name: '仓库管理',
        component: () => import('../views/warehouse/index.vue'),
        meta: {
          icon: 'ion-ios-albums',
          title: '仓库管理',
          type: [0,1,2,3],
          isHidden: false,
        },
      },
      {
        path: '/warehouse', // 默认子路由
        name: '运单管理',
        component: () => import('../views/home/index.vue'),
        meta: {
          icon: 'ion-ios-list',
          title: '运单管理',
          type: [0,1,3],
          isHidden: false,
        },
      },
      {
        path: '/users', // 默认子路由
        name: '用户管理',
        component: () => import('../views/users/index.vue'),
        meta: {
          icon: ' ion-person-stalker',
          title: '用户管理',
          type: [0,1,3],
          isHidden: false,
        },
      },
      // {
      //   path: '/car', // 默认子路由
      //   name: '车辆管理',
      //   component: () => import('../views/car_management/index.vue'),
      //   meta: {
      //     icon: 'ion-android-bus',
      //     title: '车辆管理',
      //     isHidden: false,
      //   },
      // },
      {
        path: '/online', // 默认子路由
        name: '在线监控',
        component: () => import('../views/online/index.vue'),
        meta: {
          // ion-ios-location
          icon: 'ion-ios-monitor ',
          type: [0,1,2,3],
          title: '在线监控',
          isHidden: false,
        },
      },
     
      {
        path: '/contract', // 默认子路由
        name: '合同管理',
        meta: {
          // ion-ios-location
          icon: 'ion-document-text',
          type: [2,3],
          title: '合同管理',
          isHidden: false,
        },
        children: [
          {
            path: '/contract/template',
             name: '合同模板',
            component: () => import('../views/contract/template/index.vue'),
            meta: {
              title: '合同模板',
              isHidden: false,
            }
          },
           {
            path: '/contract/pushcontract',
             name: '签署合同',
            component: () => import('../views/contract/pushContract/index.vue'),
            meta: {
              title: '签署合同',
              isHidden: false,
            }
          },
          {
            path: '/contract/staff',
             name: '员工信息',
            component: () => import('../views/contract/staff/index.vue'),
            meta: {
              title: '员工信息',
              isHidden: false,
            }
          },
           {
            path: '/contract/contract',
             name: '合同列表',
            component: () => import('../views/contract/contract/index.vue'),
            meta: {
              title: '合同列表',
              isHidden: false,
            }
          },
        ]
      },
      {
        path: '/news', // 默认子路由
        name: '行业新闻',
        component: () => import('../views/new_management/index.vue'),
        meta: {
          // ion-ios-location
          icon: 'ion-ios-list',
          type: [4],
          title: '行业新闻',
          isHidden: false,
        },
      },
      {
        path: '/companies_advisory', // 默认子路由
        name: '公司资讯',
        component: () => import('../views/companies_advisory/index.vue'),
        meta: {
          // ion-ios-location
          icon: 'ion-ios-paper',
          type: [4],
          title: '公司资讯',
          isHidden: false,
        },
      },
      {
        path: '/products', // 默认子路由
        name: '主营业务',
        component: () => import('../views/product_management/index.vue'),
        meta: {
          // ion-ios-location
          icon: 'ion-ios-paper',
         type: [4],
          title: '主营业务',
          isHidden: false,
        },
      },
      {
        path: '/contact', // 默认子路由
        name: '关于我们',
        component: () => import('../views/contactus/index.vue'),
        meta: {
          // ion-ios-location
          icon: 'ion-android-compass',
          type: [4],
          title: '联系我们',
          isHidden: false,
        },
      }
    ],
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login/index.vue'),
  },

]
const router = createRouter({
  history: createWebHashHistory(), // 路由模式
  routes, // 路由规则
})

router.beforeEach((to, from, next) => {
  const token = getToken()
  if (token) {
    next()
    if (to.path === '/') document.title = '鲲鹏顺达管理系统'
    else document.title = to.name
    nprogress.start() // 开始加载进度条
  } else {
    if (to.path === '/login') {
      // 跳转到登录页
      next()
    } else {
      next({ path: '/login' })
    }
  }
})
router.afterEach(() => {
  nprogress.done() // 开始加载进度条
})

export default router
